package com.zero.seata.service.impl;

import com.zero.seata.mapper.AccountMapper;
import com.zero.seata.service.AccountService;
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;


/**
 * AT 模式
 * @author zero
 * @ClassName AccountServiceImpl
 * @Description
 * @Date 2025/5/15 13:37
 */
@Service
public class AccountServiceImpl implements AccountService {
    private final AccountMapper mapper;

    public AccountServiceImpl(AccountMapper accountMapper) {
        this.mapper = accountMapper;
    }


    @GlobalTransactional(name =  "deduct",rollbackFor = Exception.class)
    @Override
    public void deduct(String userId, int money) {
        mapper.deduct( userId, money);
    }

    @GlobalTransactional
    @Override
    public void refund(String userId, int money) {
        mapper.refund( userId, money);
    }
}
